
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;



public class Dachuang extends JFrame implements ActionListener{
		private JTextField a1 = new JTextField(3);
		private JTextField a2 = new JTextField(3);
		private JTextField a3 = new JTextField(3);
		private JTextField a4 = new JTextField(3);
		private JTextField c1 = new JTextField(3);
		private JTextField c2 = new JTextField(3);
		
		private JTextField a5 = new JTextField(3);
		private JTextField a6 = new JTextField(3);
		private JTextField a7 = new JTextField(3);
		private JTextField a8 = new JTextField(3);
		private JTextField c3 = new JTextField(3);
		private JTextField c4 = new JTextField(3);

		
		private JButton Start = new JButton("����");
		public Dachuang() {
			JPanel p1 = new JPanel();
			p1.add(new JLabel("�᣿"));
			p1.add(a1);
			p1.add(new JLabel("��"));
			p1.add(a2);
			p1.add(new JLabel("�飿"));
			p1.add(a3);
			p1.add(new JLabel("����"));
			p1.add(a4);
			p1.add(new JLabel("ʳ��1"));
			p1.add(c1);
			p1.add(new JLabel("ʳ��2"));
			p1.add(c2);
			
			p1.add(new JLabel("�᣿"));
			p1.add(a5);
			p1.add(new JLabel("��"));
			p1.add(a6);
			p1.add(new JLabel("�飿"));
			p1.add(a7);
			p1.add(new JLabel("����"));
			p1.add(a8);
			p1.add(new JLabel("ʳ��1"));
			p1.add(c3);
			p1.add(new JLabel("ʳ��2"));
			p1.add(c4);

			p1.add(Start);
			setLayout(new GridLayout(3,1));
			add(p1);
			Start.addActionListener(this);
			
			}

		public void actionPerformed(ActionEvent e) 
		{   
			String a=a1.getText();
			String b=a2.getText();
			String c=a3.getText();
			String d=a4.getText();
			String f=c1.getText();
			String g=c2.getText();
			
			String h=a5.getText();
			String i=a6.getText();
			String j=a7.getText();
			String k=a8.getText();
			String l=c3.getText();
			String m=c4.getText();
			


			int p1=Integer.parseInt(a);
			int p2=Integer.parseInt(b);
			int p3=Integer.parseInt(c);
			int p4=Integer.parseInt(d);
			int dish1taste[]={p1,p2,p3,p4};
			String []material1={f,g};
			Dish dish1=new Dish(dish1taste,material1);
			int p5=Integer.parseInt(h);
			int p6=Integer.parseInt(i);
			int p7=Integer.parseInt(j);
			int p8=Integer.parseInt(k);
			int dish2taste[]={p5,p6,p7,p8};
			String []material2={l,m};
			Dish dish2=new Dish(dish2taste,material2);

			JOptionPane.showMessageDialog(null,"The similarity is :" + dish1.setsimilarity(dish2));
			

	}
	public static void main(String[] args) {
		// TODO �Զ���ɵķ������
		//Mathtool1 k = new Mathtool1();
		Dachuang frame1 = new Dachuang();
		frame1.setTitle("similarity");
		frame1.setSize(480,300);
		frame1.setLocationRelativeTo(null);
		frame1.setDefaultCloseOperation(EXIT_ON_CLOSE);
		frame1.setVisible(true);
		
	}
	
}


	/**
	 * Dishes generated by hbm2java
	 */
class Dish  {
		 private int[] taste = new int[4];
		 private int i;
		 private int x;
		 private int nt;
		 private String[] material;
		 private int nm;
		 private double similarity;

	    public Dish() {
	    	 i = 0;
	    	 x = 0;
	    	 nt = 0;
	    	 nm = 0;
	    	 similarity = 0;
	    }

	    public Dish(int[] taste,String [] material) {
	    	i = 0;
	    	x = 0;
	    	nt = 0;
	    	nm = 0;
	    	similarity = 0;
	    	this.taste = taste;
	    	this.material = material;
	    }
	   
	   public double setsimilarity(Dish a1){
		   for (i=0;i<4;i++){
			   if(this.taste[i]==a1.taste[i]){
				   nt++;
			   }
		   }
		   for (i=0;i<this.material.length;i++){
			   for(x=0;x<a1.material.length;x++){
				   if(this.material[i].equals(a1.material[x])){
					   	nm++;

					   	break;
				   }
			   }
		   }
		   similarity=(double)49/93*(double)nt/4+(double)44/93*(double)nm/a1.material.length;
		   return similarity;
	   		}
}
	





